class RelatoriosController < ApplicationController
  #  require 'gruff'
  #  require 'RMagick.rb'
  
  skip_before_filter :authenticate

  def initialize
    config = Configuracao.find(1)
    @tempo_paineis = config.tempo_paineis
    @tempo_relatorio = config.tempo_relatorio
    if config.exibe_msg
      @msg = config.msg
      @tempo_msg = config.tempo_msg
    else
      @msg = ""
    end
  end
  
  def msg
    render :partial => 'msg'
  end
  

  def wm
    respond_to  do |format|
      format.html
    end
  end
  
  def wm_partial
    @status = [8,10,15]
    @transportes = Transporte.find_all_by_status_id([8,10,15], :order => "box asc, status_id desc")
    @depositos = Deposito.find(:all, :order => "qtbox desc")
    render :partial => 'depositos'
  end
  
  def wm_geral
    respond_to  do |format|
      format.html
    end
  end
  
  def wm_geral_partial
    @status = [1,3,12,13,14]
    @transportes = Transporte.find_all_by_status_id([1,3,4,12,13,14],  :order => "box asc, status_id desc")
    @depositos = Deposito.find(:all, :order => "qtbox desc")
    render :partial => 'depositos'
  end
  
  def celcli
    respond_to  do |format|
      format.html
    end
  end
  
  def celcli_partial
    @status = [8,10,15]   
    @transportes = Transporte.find_all_by_status_id([8,10,15],  :order => "box asc, status_id desc")
    @depositos = Deposito.find(:all, :order => "qtbox desc")
    render :partial => 'depositos'
  end
  
  def resumo
    respond_to do |format|
      format.html
    end
  end
  
  def resumo_partial
    @depositos = Deposito.find(:all, :order => "qtbox desc")
    #graf_faturamento
    render :partial => 'resumo'
  end

  #  def graf_faturamento
  #    g = Gruff::Line.new('408x306',false)
  #    #g = Gruff::Bar.new('1024x800')
  #    g.theme_keynote
  #    #    g.theme = {
  #    #      :colors => ['#ff6600', '#3bb000', '#1e90ff', '#efba00', '#0aaafd'],
  #    #      :marker_color => '#aaa',
  #    #      :background_colors => ['#eaeaea', '#fff']
  #    #    }
  #    g.hide_title = false
  #    g.hide_legend = false
  #    g.font = File.expand_path('path/to/font.ttf', RAILS_ROOT)
  #    g.title = "Faturado"
  #    
  #    #Gerando grafico para o CD
  #    @depositos = Deposito.find(:all)
  ##    @depositos.each do |d|
  ##      g.data(d.nome,d.grafico_faturamento_dia_s_d([4,9],d.id))
  ##    end
  #
  #    g.data("thiago",[0.1,0.1,0.1])
  #    g.data("sampaio",[0.1,0.1,0.1])
  #    
  #    #    @deposito.grafico_faturamento_dia_d(@deposito.id,[4,9])
  #    #    g.data(@deposito.nome, [0,1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,0,20,21,22,23,24])
  #    #    g.data("Jaca", [4, 8, 7, 9, 8, 9])
  #    #    g.data("Cuité", [2, 3, 1, 5, 6, 8])
  #    #    g.data("Pitomba", [9, 9, 10, 8, 7, 9])
  #
  #    #    g.labels = {0 => '0h', 1 => '1h', 2 => '2h', 3 => '3h', 4 => '4h',5 => '5h',6 => '6h',
  #    #      7 => '7h', 8 => '8h', 9 => '9h', 10 => '10h', 11 => '11h', 12 => '12h', 13 => '13h', 14 => '14h',
  #    #      15 => '15h', 16 => '16h', 17 => '17h', 18 => '18h', 19 => '19h', 20 => '20h', 21 => '21h', 22 => '22h',
  #    #      23 => '23h', 24 => '24h'
  #    #    }
  #
  #    g.labels = {0 => '0h', 2 => '2h', 4 => '4h',6 => '6h',
  #      8 => '8h',10 => '10h', 12 => '12h',14 => '14h',
  #      16 => '16h', 18 => '18h',  20 => '20h', 22 => '22h',
  #      24 => '24h'
  #    }
  #    g.write('c:/teste.png')
  #    #send_data(g.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "site-stats.png")
  #    #send_data(g.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "gruff.png")    
  #  end
  
  def faturamento_mes
    @depositos = Deposito.find(:all)
    #@transportes = Transporte.find_all_by_status_id([4,9], :conditions => ["ended_at LIKE ?","%#{Time.now.year}-#{Time.now.month}%"])
    respond_to do |format|
      format.html
    end
  end
end
